package com.haoshuang.zhouzhoubang.ui.page.welfare.tool.detail

import android.content.Context
import android.os.Bundle
import com.haoshuang.zhouzhoubang.R
import com.haoshuang.zhouzhoubang.databinding.ActivityToolUseRecordDetailBinding
import com.haoshuang.zhouzhoubang.model.bean.ToolUseRecordBean
import com.lxj.xpopup.XPopup
import com.lxj.xpopup.core.ImageViewerPopupView
import com.lxj.xpopup.interfaces.OnSrcViewUpdateListener
import com.lxj.xpopup.util.SmartGlideImageLoader
import com.mufeng.libs.base.BaseVMActivity
import com.mufeng.libs.core.setOnItemClick
import com.mufeng.libs.utils.view.click
import com.mufeng.libs.utils.startPage
import com.mufeng.libs.utils.view.vertical

/**
 *  
 */
class ToolUseRecordDetailActivity : BaseVMActivity<ToolUseRecordDetailViewModel, ActivityToolUseRecordDetailBinding>() {

    companion object {
        fun launch(context: Context){
            context.startPage<ToolUseRecordDetailActivity>()
        }
    }

    private val data = arrayListOf<String>()
    private val adapter = ToolUseRecordDetailImageAdapter(data)

    private val bean by lazy {
        intent.getParcelableExtra<ToolUseRecordBean>("toolUseRecordBean")
    }

    override fun initView(savedInstanceState: Bundle?) {
        binding.titleBar.title = "明细详情"
        binding.titleBar.leftImageView().click { finish() }

        binding.tvName.text = bean?.title
        binding.tvTime.text = bean?.add_time
        binding.tvNum.text = bean?.number

        data.addAll(bean?.images?: emptyList())
        binding.recyclerView.vertical(3).adapter = adapter
        adapter.setOnItemClick { view, position, item ->
            XPopup.Builder(mActivity)
                .asImageViewer(view.findViewById(R.id.rivImage), position,
                    data as List<Any>?,
                    OnSrcViewUpdateListener { popupView, position -> popupView.updateSrcView(binding.recyclerView.getChildAt(position).findViewById(R.id.rivImage)!!) }, SmartGlideImageLoader())
                .show()
        }
    }

    override fun initData() {
    }

    override fun startObserve() {
    }

}